function initPage(pageNo,totalCount,arr){
    // 获取分页器实例对象
    var myPager = $('#myPager').data('zui.pager');
    //设置当前页码为 4，并同时设置记录总数为 100， 每页记录数目为 30
    myPager.set(pageNo, totalCount, 5);
    renderSubscribeList(arr);
}
$('#myPager').pager({
    onPageChange: function(state, oldState) {
        if (state.page !== oldState.page) {
            // console.log('页码从', oldState.page, '变更为', state.page);
            queryBtn(state.page);

        }
    }
});
function renderSubscribeList(arr){
    let str = '';
    for (let i = 0; i < arr.length; i++) {
        let a  = arr[i];
        str += `<tr>
                <td>${a.asseTime}</td>
                <td>${a.username}</td>
                <td>${a.fieldName}</td>
                <td>${a.score}</td>
                <td  style="text-align: left">
                    <button onclick="subInfo(${a.id})"
                    type="button" data-toggle="modal" data-target="#myModal2" 
                    id="updateBtn"  
                    class="btn btn-info updateBtn btn-primary">
                    查看报告</button>
                  
                </td>
            </tr>`;


    }
    $('#tbody')[0].innerHTML = str;
}
function subInfo(id){

    console.log(id);
    $.ajax({
        url:config.url + "/assessment/assessmentForOne",
        dataType:'json',
        xhrFields: {
            withCredentials: true
        },
        data:{
            id:id
        },
        crossDomain: true,
        type:'GET',
        success:function(resp) {
            var consInfo = resp.data;
            var str = '';
            str+=
                `
                    <ul class="list-group">
                            <li class="list-group-item">测评结果:&nbsp;&nbsp;${consInfo.asseResult}</li>
                            <li class="list-group-item">报告内容:&nbsp;&nbsp;${consInfo.asseInfo}</li>
                        </ul>
                `
            $('#sub-info-div')[0].innerHTML = str;
        },
        error:function() {
        }
    });
}
var subId;
function submitBanForm(){
    $.ajax({
        url: config.url + "/sub/ban",
        dataType: 'json',
        xhrFields: {
            withCredentials: true
        },
        data: {
            id: subId
        },
        crossDomain: true,
        type: 'GET',
        success: function (resp) {
            alert(resp.msg);
            location.reload();
        },
        error: function () {
        }
    });
}
queryBtn(1);
function queryBtn(i){
    let score1 = $("#cons-input").val();
    let score2 = $("#user-input").val();
    let date1 = $("#date-input1").val();
    let date2 = $("#date-input2").val();
    if (date1 == null || date1 == ""){
        date1 == "";
    }
    if (date2 == null || date2 == ""){
        date2 == "";
    }
    $.ajax({
        url:config.url + "/assessment/queryForCondition",
        dataType:'json',
        xhrFields: {
            withCredentials: true
        },
        data:{
            score1:score1,
            score2:score2,
            date1:date1,
            date2:date2,
            pageNo:i
        },
        crossDomain: true,
        type:'POST',
        success:function(resp) {
            var totalCount = resp.data.totalCount;
            renderSubscribeList(resp.data.list);
            initPage(resp.pageNo,totalCount,resp.data.list);
        },
        error:function() {
        }
    });
}
